var tddjs = tddjs || {};

tddjs.AddController = function (formView, backend, listController) {
	this.view = formView;
	this.backend = backend;
	this.listController = listController;
	jQuery(this.view).bind("click", function(event) {
		this.addTask();
	}.bind(this));
};
tddjs.AddController.prototype = {

	addTask : function() {
		var input = this.view.childNodes[0];
		var taskName = input.getAttribute("value");
		this.backend.add(taskName, function(err,item) {
			if(!err) {
				this.listController.taskAdded(taskName);
				input.setAttribute("");
			}
		}.bind(this));
	}
};